# Mostly written by Jonathan Larmour, Red Hat, Inc.
# Reference to ecos.mak added by John Dallaway, eCosCentric Limited, 2003-01-20
# This file is in the public domain and may be used for any purpose

# Usage:   make INSTALL_DIR=/path/to/ecos/install

MAIN_FILE_NAME = main
DEVENV = c:\uproc\devenv
# INSTALL_DIR=$$(INSTALL_DIR) # override on make command line           

# INSTALL_DIR=${DEVENV}/arm/ecos_build/ecos_mikroproclabor_install
INSTALL_DIR=${DEVENV}/arm/ecos_build/ecos_default_lpc2106_install

include $(INSTALL_DIR)/include/pkgconf/ecos.mak

XCC           = $(ECOS_COMMAND_PREFIX)gcc
XCXX          = $(XCC)
XLD           = $(XCC)

CFLAGS        = -I. -I$(INSTALL_DIR)/include -I$(DEVENV)/common
CXXFLAGS      = $(CFLAGS)
LDFLAGS       = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld -Wl,-M=map.txt

# Project Files

PROJECT_OUTPUTS = $(MAIN_FILE_NAME).o

#APIS - platform.h must be included in the project
#PROJECT_OUTPUTS+= $(DEVENV)/common/com_r04_s01b.o
#PROJECT_OUTPUTS+= $(DEVENV)/common/dpy_trm_s01.o
PROJECT_OUTPUTS+= com_r04_s01b.o
PROJECT_OUTPUTS+= dpy_trm_s01.o
PROJECT_OUTPUTS+= Timer.o
PROJECT_OUTPUTS+= UserTasks.o

# RULES

.PHONY: all clean

all: $(MAIN_FILE_NAME)
	arm-elf-objcopy -O ihex $(MAIN_FILE_NAME) $(MAIN_FILE_NAME).hex
	arm-elf-objdump -h $(MAIN_FILE_NAME)
 
clean:
	-rm -f $(MAIN_FILE_NAME) *.o
	-rm -f $(MAIN_FILE_NAME) *.hex
	-rm -f map.txt
        

%.o: %.c
	$(XCC) -c -o $*.o $(CFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cxx
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.C
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cc
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

$(MAIN_FILE_NAME): $(PROJECT_OUTPUTS) 
	$(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ $(PROJECT_OUTPUTS)